<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="author" content="邵铭">
    <title></title>
    <style>
        * {
            box-sizing: border-box;
        }
        
        body {
            margin: 0;
        }
        
        .box {
            width: 620px;
            height: 200px;
            border: 1px solid #68AFD9;
            margin: 0 auto;
            position: relative;
        }
        
        textarea {
            width: 600px;
            height: 100px;
            border: solid 1px #ddd;
            margin-left: 10px;
            margin-top: 50px;
        }
        
        textarea:focus {
            outline: none;
            border: 1px solid orange;
        }
        
        button {
            width: 100px;
            height: 30px;
            color: white;
            background-color: #ff8140;
            border: none;
            display: block;
            position: absolute;
            margin-top: 10px;
            right: 10px;
        }
        
        p {
            position: absolute;
            right: 10px;
            display: none;
        }
    </style>
</head>

<body>
    <div class="box">
        <p>已输入<strong>0</strong>字</p>
        <textarea></textarea>
        <button type="button">发布</button>
    </div>
    <script src="./jquery.js"></script>
</body>

</html>
<script>
    $("textarea").keyup(function () {
        var zishu = $(this).val().length;
        $("strong").text($(this).val().length);

        if (zishu > 0) {
            $('p').show();
        }
        if (zishu >= 140) {
            $("strong").css('color', 'red');
            // $("textarea").val(val);
        } else {
            $("strong").css('color', '');
        }

        // $("textarea").each(function(index){
        //      var str = $(this).eq(index).val();
        //       console.log($(this).eq(index).val());
        //         if (str.charCodeAt(index) > 255) {
        //              $("strong").text($(this).val().length);
        //         } else {
        //              $("strong").text($(this).val().length+0.5); 
        //         }
        // })



    });

</script>